#coding:utf-8
# @Time    : 2018/10/2 1:56
# @Author  : 0x007er
# @File    : progresszgrab.py
# @Software: PyCharm
import requests
import demjson
import time
res = requests.get('http://104.168.159.24:5000/servers',timeout=10)
s = f = 0
def t(ip):
    global s,f
    try:
        res = requests.get('http://' + ip + ':5000/zgrabstatus')
        s += res.json()['success']
        f += res.json()['failure']
        print ip,res.text
    except Exception as e:
        print(ip,e)
servers = demjson.decode(res.text)
for server in servers:
    ip = server[1]
    t(ip)
print 'SUCCESS',s,'FAILURE',f,'COUNT',s+f,'ERROR',(float(f)/float(s+f)) * 100 , '%'
time.sleep(10)